package com.slz3.business.module.goodsManagement.gooTypeLevel1.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.goodsManagement.gooTypeLevel1.domain.GooTypeLevel1;
import com.slz3.business.module.goodsManagement.gooTypeLevel1.domain.GooTypeLevel1Factory;
import com.slz3.business.module.goodsManagement.gooTypeLevel1.steward.GooTypeLevel1Specification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class GooTypeLevel1ServiceImpl implements GooTypeLevel1Service {

    @Override
    public GooTypeLevel1 save(GooTypeLevel1 gooTypeLevel1) {
        return Repositorys.gooTypeLevel1.save(GooTypeLevel1Factory.initBaseFields(gooTypeLevel1));
    }

    @Override
    public Page<GooTypeLevel1> page(MultiValueMap<String, String> params) {
        Page<GooTypeLevel1> gooTypeLevel1Page = Repositorys.gooTypeLevel1.findAll(
                GooTypeLevel1Specification.findJoin(params), PageableSteward.extract(params)
        );
        return gooTypeLevel1Page;
    }

    @Override
    public GooTypeLevel1 modify(GooTypeLevel1 gooTypeLevel1New) {
        return Repositorys.gooTypeLevel1.saveAndFlush(GooTypeLevel1Factory.initBaseFields(gooTypeLevel1New));
    }

    @Override
    public Optional<GooTypeLevel1> single(UUID uuid) {
        return Repositorys.gooTypeLevel1.findById(uuid);
    }

    @Override
    public List<GooTypeLevel1> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.gooTypeLevel1.findAllById(uuids);
    }

    @Override
    public List<GooTypeLevel1> delete(List<GooTypeLevel1> gooTypeLevel1List) {
        gooTypeLevel1List.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            GooTypeLevel1Factory.initBaseFields(item);
        });
        return Services.gooTypeLevel1Transactional.batchModify(gooTypeLevel1List);
    }

}
